package cqut.wys.config;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * 数据源选择切面
 * --------神兽出没--------/
 *   ┌─┐     ┌─┐
 * ┌─┘─┴─────┘─┴─┐
 * │      ─      │
 * │  ┬─┘   └─┬  │
 * │             │
 * │      ┴      │  Code is far away from bug with the animal protecting
 * └───┐      ┌──┘  神兽保佑,代码无bug
 *     │      │
 *     │      └──────┐
 *     │             ├┐
 *     │             ┌┘
 *     └┐ ┐ ┌───┬─┐ ┌┘
 *      │ ┤ ┤   │ ┤ ┤
 *      └─┴─┘   └─┴─┘
 * --------感觉萌萌哒--------/
 *
 * @author wuyoushan
 * @date 2018/2/28
 */
@Aspect
@Component
public class DatasourceApset {

    private static final String USER = "user";
    private static final String NEWS = "news";

    //数据源选择,news包选择news库
    @Pointcut("execution(* cqut.wys.dao.mapper.news.*.*(..))")
    public void before(){
    }

    @Before("before()")
    public void selectDb(){
        if (DataSourceContextHolder.getDbType() == null) {
            DataSourceContextHolder.setDbType(NEWS);
        }
    }
}
